
const { list } = require('./src/mock')
const bodyParser = require('body-parser')

module.exports = {
	devServer: {
		before(app) {
			app.use(bodyParser.json())
			app.get('/api/list', (req, res) => res.send({ code: 200, data: list }))

			app.post('/api/detail', (req, res) => {
				const { id } = req.body
				const item = list.find(v => v.id === id)
				if (item) {
					res.send({
						code: 200,
						data: item
					})
				} else {
					res.send({
						code: 404,
						data: null,
						mess: '数据不存在或者已经下架'
					})
				}
			})
		}
	}
}